package org.se.scut.pinterest.mina.handler;

import org.apache.mina.core.session.IoSession;
import org.se.scut.pinterest.mina.codec.msg.AllPictureTypeMessage;
import org.se.scut.pinterest.mina.codec.msg.Message;
import org.se.scut.pinterest.mina.codec.msg.PictureUploadMessage;
import org.se.scut.pinterest.mina.codec.msg.PicturesGetMessage;
import org.se.scut.pinterest.mina.handler.observer.IMessageObserver;
import org.se.scut.pinterest.mina.handler.observer.MessageContainer;
import org.se.scut.pinterest.mina.handler.observer.MessageOperatorType;

public class MessageHandlerProxy extends MessageContainer {

	{
		registe(PictureUploadMessage.class.hashCode(), new PictureUploadHandler());
		registe(AllPictureTypeMessage.class.hashCode(), new AllPictureTypeHandler());
		registe(PicturesGetMessage.class.hashCode(), new PicturesGetHandler());
	}

	@Override
	public void callObserver(IoSession session, Message msg, MessageOperatorType type) {
		synchronized (mObservers) {
			IMessageObserver observer = mObservers.get((Integer)(msg.getClass().hashCode()));
			if (observer != null) {
				observer.onMessageChange(session , msg, type);
			}
		}
		
	}
	
}
